﻿<?php
    echo "hello.";
    $username = $_POST["user"];
    $password = $_POST["password"];
    $confirm = $_POST["password1"];
    $email = $_POST["email"];
    $userage = $_POST["age"];
    $usersex = $_POST["sex"];
    $verify = $_POST["verify"];
		echo $username;
        echo $password;
        echo $confirm;
        echo $email;
        echo $userage;
        echo $usersex;
        echo $verify;
    if($username=="" || $password=="" || $confirm=="" || $email=="")
    {
        echo '<script>alert("请确认信息的完整性！");history.go(-1);</script>';	//为什么单引号和双引号不一样
    }
    else if($password != $confirm)
    {
        echo '<script>alert("密码不一致！");history.go(-1);</script>';
    }
    else
    {
        require("Include/conn.php");
        $sql = "SELECT `user_name` FROM `pw_user` WHERE `user_name`='$username';";
        $result = mysqli_query($link,$sql);
        if (!$result)
        {
            die(mysqli_error($link));
        }
        $num = mysqli_num_rows($result);
        if($num)
        {//说明该用户已经存在
            echo '<script>alert("该用户已存在，请登录！");history.go(-1);</script>';
        }
        else
        {
            $sql_insert = "INSERT INTO `pw_user` (`user_name`,`user_pwd`,`user_email`,`user_sex`,`user_age`) VALUES ('$username','$password','$email','$usersex',$userage);";
            $result_insert = mysqli_query($link,$sql_insert);

            if($result_insert){
                echo '<script>alert("注册成功！");window.location.href = \'index.php\';</script>';
            }
            else{
                echo '<script>alert("系统繁忙，请稍后！");window.location.href = \'register.html\';</script>';
            }
        }
    }
?>